<template>
  <!-- 竣工项目归档计划 -->
  <base-breadcrumb class="archivePlan-container">
    <searchData :searchData="searchArr" @search="handleSearch" @autoBranchSelected="autoBranchSelected"></searchData>
    <a-card :bordered="false">
      <!-- <title-name title="竣工项目归档计划" /> -->
     <list-table
        ref="table"
        row-key="id"
        :columns="columns"
        :request="loadData"
        :alert="true"
      >
        <template slot="action" slot-scope="text, record">
          <div class="pub-table-list-action">
            <span v-btnPermission="'oa_007_loo_02'" @click="handleUpdate(record, 'look')">查看</span>
            <span v-btnPermission="'oa_007_ver_01'" v-if="record.branchArchiveConfirmNum < record.archiveProjectNum" @click="handleUpdate(record, 'check')">核定归档</span>
          </div>
        </template>
      </list-table>
    </a-card>
  </base-breadcrumb>
</template>

<script>
// import { STable } from '@/components' // 表格
import SelectSubCompany from '@/components/Select/SelectSubCompany' // 分公司
import { getPlanList } from '@/api/office/archiveManage/archivePlan.js'
import Vue from 'vue'
import OrgTreeSelect from '@/components/OrgTreeSelect'

const userInfo = Vue.getAcloudProvider().getUserInfo()

const searchArr = [
  // {
  //   name: '分公司',
  //   valueKey: 'brandOrgId',
  //   type: SelectSubCompany,
  //   autoSelected: userInfo?.currentPost?.code === 'BC' // 分公司级别的岗位，自动选择
  // },
  {
    name: '所属单位',
    valueKey: 'searchQuery',
    type: OrgTreeSelect,
  },
  {
    name: '归档年度',
    value: 'archiveYear',
    type: 'year',
    placeholder: '请选择',
  },
]
const columns = [
  {
    title: '序号',
    width: 80,
    dataIndex: 'index',
    customRender() {
      return arguments[2] + 1
    },
  },
  {
    title: '分公司',
    dataIndex: 'branchOrgName',
  },
  {
    title: '归档年度',
    dataIndex: 'archiveYear',
  },
  {
    title: '可归档项目数',
    dataIndex: 'archiveProjectNum',
  },
  {
    title: '项目部确认可归档数',
    dataIndex: 'projectArchiveConfirmNum',
  },
  {
    title: '分公司已核定归档项目数',
    dataIndex: 'branchArchiveConfirmNum',
  },
  {
    title: '操作',
    dataIndex: 'action',
    width: '180px',
    align: 'center',
    scopedSlots: { customRender: 'action' },
  },
]
export default {
  name:'a'+Date.now(),

  components: {
    // STable,
  },
  data() {
    return {
      searchArr,
      columns: columns,
      queryParam: {},
    }
  },
  methods: {
    autoBranchSelected(val) {
      this.queryParam = {
        ...this.queryParam,
        brandOrgId: val
      }
      if(userInfo?.currentPost?.code === 'BC') {
        this.refreshTable()
      }
    },
    /**
     * 处理数据的相关操作（增删改查）
     */
    handleUpdate(data, pageType) {
      const commonHandler = () => {
        this.$router.push({
          path: '/conference/archiveManage/archivePlan/update',
          query: {
            id: data.id || '',
            pageType: pageType,
            branchOrgId: data.branchOrgId || '',
            archiveYear: data.archiveYear || '',
          },
        })
      }
      const actionMap = {
        check: commonHandler,
        look: commonHandler,
      }
      actionMap[pageType] && actionMap[pageType]()
    },
    handleSearch(val = {}) {
      this.queryParam = {
        ...val,
      }
      this.refreshTable()
    },
    refreshTable() {
      this.$refs.table.refresh(true)
    },
    async loadData(parameter) {
      const requestParameters = Object.assign({}, { ...parameter }, { query: this.queryParam })
      return getPlanList(requestParameters)
    },
  },
}
</script>

<style>
</style>